package com.bdqn.boot.yuanshen.controller;

import com.bdqn.boot.yuanshen.bean.Interaction;
import com.bdqn.boot.yuanshen.service.InteractionService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zwt
 * @version 1.0
 * @className InteractionController
 * @description 用户互动控制器
 * @date 2025/3/12 09:53
 */
@Slf4j
@RestController
@CrossOrigin

public class InteractionController {

    @Autowired
    private InteractionService interactionService;

    @GetMapping("/interactions")
    public PageInfo<Interaction> getInteractions(@RequestParam(defaultValue = "1") int pageNum,
                                                 @RequestParam(defaultValue = "10") int pageSize) {
        return interactionService.getInteractions(pageNum, pageSize);
    }

    @GetMapping("/interactions/{id}")
    public Interaction getInteractionsByUserId(@PathVariable Integer id) {
        return interactionService.getById(id);
    }

    @PostMapping("/interactions")
    public String saveInteraction(@RequestBody Interaction interaction) {
        if (interaction.getId() == null || interaction.getId() == 0) {
            interactionService.addInteraction(interaction);
            return "success";
        } else {
            interactionService.updateInteraction(interaction);
            return "update";
        }
    }

    @DeleteMapping("/interactions/{id}")
    public String deleteInteraction(@PathVariable Integer id) {
        interactionService.deleteInteraction(id);
        return "delete";
    }


}